package com.cu.jiekong.service;

import com.alibaba.fastjson.JSONObject;
import com.cu.jiekong.frame.model.Ret;
import com.cu.jiekong.model.BorrowAuditorInfo;
import com.cu.jiekong.model.TongdunRiskInfo;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 审核处理类
 *
 * @author jintian
 * @date 11:34
 */
@Service
public class AuditorService {

    @Autowired
    private TongDunRiskInfoService tongDunRiskInfoService;

    @Autowired
    private AmqpTemplate amqpTemplate;

    /**
     * 机审借款订单
     *
     * @param borrowAuditorInfo
     * @return
     */
    public void auditorBorrow(BorrowAuditorInfo borrowAuditorInfo) {
        // 获取同盾风险数据
        TongdunRiskInfo riskInfo = tongDunRiskInfoService.queryTongDunRisk(borrowAuditorInfo.getBorrowUserName(), borrowAuditorInfo.getBorrowUser() + "", borrowAuditorInfo.getBorrowUserMobile());
        // 根据同盾风险信息分析是否给予放款
        if (riskInfo.getOneYearOdueNum() != null && riskInfo.getOneYearOdueNum() > 2) {
            // 推送消息给交易系统
            JSONObject json = new JSONObject();
            json.put("code", "fail");
            json.put("borrowId", borrowAuditorInfo.getBorrowId());
            json.put("msg", "最近一年内预期次数过多机审不通过");

            amqpTemplate.convertAndSend("borrowAuditor", json.toJSONString());
        }
    }
}
